package com.ljfiction.book.pay;

import android.content.Context;
import android.util.Log;

import com.ljfiction.book.tools.Tool;
import com.tencent.mm.opensdk.modelpay.PayReq;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;


/**
 * Created by zjc on 2016/7/12.
 */
public class WeiXin {

    public static final String APP_ID = "wx3c440c21cdf7452b";
    public  void pay(Context context,Parame parame){
        Log.v("wx","调支付");
       IWXAPI api = WXAPIFactory.createWXAPI(context,parame.appId );
        api.registerApp(parame.appId);
        final PayReq req = new PayReq();
        req.appId			= parame.appId;
        req.partnerId		= parame.partnerId;
        req.prepayId		= parame.prepayId;
        req.nonceStr		= parame.nonceStr;
        req.timeStamp		= parame.timeStamp;
        req.packageValue	= parame.packageValue;
        req.sign			= parame.sign;
        req.signType        ="md5";
        req.extData		= parame.extData; // optional
        Tool.showToast("正常调起支付", context);
        // 在支付之前，如果应用没有注册到微信，应该先调用IWXMsg.registerApp将应用注册到微信
        boolean s=api.sendReq(req);

    }
    public static class Parame{
        private  String appId=APP_ID;
        private  String partnerId="";
        private  String prepayId="";
        private  String nonceStr="";
        private  String timeStamp="";
        private  String packageValue="Sign=WXPay";
        private  String sign="";
        private  String extData="";

        public String getAppId() {
            return appId;
        }

        public void setAppId(String appId) {
            this.appId = appId;
        }

        public String getPartnerId() {
            return partnerId;
        }

        public void setPartnerId(String partnerId) {
            this.partnerId = partnerId;
        }

        public String getPrepayId() {
            return prepayId;
        }

        public void setPrepayId(String prepayId) {
            this.prepayId = prepayId;
        }

        public String getNonceStr() {
            return nonceStr;
        }

        public void setNonceStr(String nonceStr) {
            this.nonceStr = nonceStr;
        }

        public String getTimeStamp() {
            return timeStamp;
        }

        public void setTimeStamp(String timeStamp) {
            this.timeStamp = timeStamp;
        }

        public String getPackageValue() {
            return packageValue;
        }

        public void setPackageValue(String packageValue) {
            this.packageValue = packageValue;
        }

        public String getSign() {
            return sign;
        }

        public void setSign(String sign) {
            this.sign = sign;
        }

        public String getExtData() {
            return extData;
        }

        public void setExtData(String extData) {
            this.extData = extData;
        }
    }
}
